const fs = require("fs");
const path = require("path");

function render(res,url,status=200) {
  res.writeHead(status, { "Content-Type": "text/html;charset=utf-8" });
  fs.readFile(path.join(__dirname, url), "utf-8", (err, data) => {
    if (err) {
      console.log("页面读取失败");
    } else {
      res.end(data);
    }
  });
}

function router(url, res) {
  if (url === "/home") {
    render(res, "./static/home.html");
  } else if (url === "/login") {
    render(res, "./static/login.html");
  } else {
    render(res, "./static/404.html",404);
  }
}
module.exports = router;
